package io.kiki.stack.netty.channelManager;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;

/**
 * a callable definition for healing Channel in {@link Pool}
 */
@Slf4j
@Setter
@Getter
public class HealPoolTask implements Callable<Integer> {
    private final ChannelManagerImpl channelManager;
    private final Url url;
    private final Pool pool;

    public HealPoolTask(ChannelManagerImpl channelManager, Url url, Pool pool) {
        this.channelManager = channelManager;
        this.url = url;
        this.pool = pool;
    }

    @Override
    public Integer call() throws Exception {
        channelManager.doCreatePool(this.pool, this.url, 0);
        return this.pool.size();
    }
}
